home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
SPACE 1
/
SPACE - Library 1 - Volume 1.iso
/
program
/
386
/
utility
/
speedtst.s
< prev
next >
Wrap
Text File
|
1985-11-19
|
10KB
|
231 lines
; Program Name: SPEEDTST.S
; Version: 1.006
; Assembly Instructions:
; Assemble in "PC-relative" mode and save with a TTP extension.
; Function:
; Spawn the TOS or PRG process typed on the command line. Create a disk
; file which is to be identified by the name of the spawned program with a
; DAT suffix. The disk file is to reside in the same directory as does the
; spawned process.
; Calculate the spawned program's load and execution times and store them
; in the file. If the spawned process directs output to the video screen via
; GEMDOS function $9, redirect that output to the file.
; Execution Instructions:
; SPEEDTST.TTP will not execute unless the custom traps in program
; TRAPS.PRG have previously been installed.
; Execute from the desktop. Type the name of an executable file which
; has a TOS or PRG extension on SPEEDTST.TTP's input parameter line. The
; name of the program you type on the parameter line must be in the same
; directory as is SPEEDTST.TTP. The program must terminate with GEMDOS
; function $4C, and, via that function, it must pass to SPEEDTST.TTP the
; word length portion of the value that was in memory location $4BA
; immediately after it was loaded.
; The longword value in $4BA can be obtained by invoking custom trap #3
; (get_time). SPEEDTST.TTP uses the word length portion of that value,
; which is returned in D0 by GEMDOS $4C, to calculate the spawned program's
; load and execution times.
; If the spawned program contains any instructions that cause it to pause,
; such as those that wait for a keypress or some other event, those should be
; commented out, and the program should be assembled especially for the speed
; test. Otherwise the execution time computed by SPEEDTEST.TTP will include
; the time that the spawned program was waiting for the event to occur.
; If custom trap #8 is used to terminate the spawned program, the trap
; will execute a wait_for_keypress algorithm when the program is executed from
; the desktop, but it will omit the wait algorithm when the program is spawned
; by SPEEDTST.TTP. In addition, trap #8 will return the after-load value to
; SPEEDTST.TTP and terminate the spawned program with GEMDOS function $4C.
; Both trap #8 and SPEEDTST.TTP require that the spawned program be
; initialized with custom trap #6 or a similar algorithm. See TRAPS.S for
; details about custom traps #6 and #8.
release_excess_memory:
lea -$82(pc), a3 ; Put "command line" address in A3.
lea -$80(a3), a1 ; Put "basepage" address in A1.
lea program_end, a0 ; Put "end of program" address in A0.
trap #6 ; Calculate program size and release memory.
; NOTE: A local stack is not declared in PRG_5AP.TOS. Because of the long
; string that is printed by that program, this program will bomb when
; it spawns PRG_5AP.TOS, if a local stack is not declared here.
lea stack, a7 ; Point A7 to this program's stack.
process_command_line:
lea command_line, a4 ; Fetch location to contain command line.
movem.l (a3), d0-d3 ; Move 16 bytes of command line to 4 registers.
movem.l d0-d3, (a4) ; Move them to address "command_line".
move.b (a3)+, d0 ; Fetch command line ASCII character count.
ext.w d0 ; Extend to word for next instruction.
move.b #0, 1(a4,d0.w) ; Store a null at end of string.
lea program_name, a0 ; Fetch address of pointer to command line.
move.l a3, (a0) ; Store address of command line string at
; pointer.
move.b #0, 0(a3,d0.w) ; Replace $0D at end of command line input
; in basepage with a NULL.
insert_filename_suffix:
move.b #$44, -2(a4,d0.w) ; Insert letter 'D'.
move.b #$41, -1(a4,d0.w) ; Insert letter 'A'.
move.b #$54, 0(a4,d0.w) ; Insert letter 'T'.
create_file:
move.w #0, -(sp) ; File attribute = read/write.
pea filename ; Will be name of spawned process + .DAT.
move.w #$3C, -(sp) ; Function = f_create = GEMDOS $3C.
trap #1 ; File handle is returned in D0.
addq.l #8, sp
lea file_handle, a0 ; Store returned file handle.
move.w d0, (a0)
redirect_output: ; Exchange file handle with screen's handle.
move.w file_handle, -(sp) ; This is the disk file's handle.
move.w #1, -(sp) ; This is the video screen's handle.
move.w #$46, -(sp) ; Function = f_force = GEMDOS $46.
trap #1
addq.l #6, sp
prepare_stack_for_load_and_execute_program:
pea environ_string
pea command_string
pea (a3) ; Push address of program name string.
move.w #0, -(sp)
move.w #$4B, -(sp) ; Function = GEMDOS $4B = p_exec.
get_start_time:
lea start_time, a3 ; Fetch address of variable "start_time".
trap #3 ; Returns value of system clock in D0.
move.w d0, (a3) ; Save start time.
load_and_execute_program:
trap #1
move.w d0, d3 ; Copy after-load value to D3 for calculation.
get_end_time:
trap #3 ; Returns value of system clock in D0.
move.w d0, d5 ; Copy to D5 for calculation.
sub.w d3, d5 ; Subtract after-load time from end time.
ext.l d5 ; Extend to 32 bits.
reposition_stack_pointer:
lea $10(sp), sp
get_drive:
move.w #$19, -(sp) ; Function = dgetdrv = GEMDOS $19.
trap #1 ; Returns 0 for drive A, 1 for B, etc.
addq.l #2, sp
add.b #$41, d0 ; Add ASCII value for A to compute ASCII
lea drive, a0 ; letter code for the drive value returned.
move.b d0, (a0) ; Save drives ASCII leter code.
print_heading:
lea heading, a0
bsr print_string
lea program_name, a0 ; Fetch address of program name string.
movea.l (a0), a0
bsr print_string
print_drive_for_spawned_program:
lea drive_msg, a0
bsr print_string
compute_load_time:
lea load_time_msg, a0
bsr print_string
lea start_time, a3
sub.w (a3), d3 ; Subtract start time from after-load time.
ext.l d3 ; Extent to 32 bits.
multiply_by_five: ; Convert to milliseconds.
move.l d3, d0 ; Save a copy to add.
asl.l #2, d3 ; Shift to multiply by 4.
add.l d0, d3 ; To complete multiplication by 5.
print_load_time:
cmpi.l #999, d3 ; If load time is less than 1000, then
bgt no_space ; print a leading blank space for output
lea space, a0 ; alignment.
bsr print_string
cmpi.l #99, d3 ; If load time is less than 100, then
bgt no_space ; print another leading blank space.
lea space, a0
bsr print_string
no_space:
move.l d3, d1 ; Copy load time to D1 for decimal conversion.
trap #4 ; Returns address of decimal string in A0.
bsr.s print_string
lea units_label, a0
bsr.s print_string
compute_execution_time: ; D5 already contains the execution time.
lea execute_time_msg, a0; Here, it must only be multiplied by 5 to
bsr.s print_string ; be converted to milliseconds.
move.l d5, d0 ; Save a copy to add.
asl.l #2, d5 ; Shift to multiply by 4.
add.l d0, d5 ; To complete multiplication by 5.
print_execution_time:
cmpi.l #999, d5 ; If execute time is less than 1000, then
bgt _no_space ; print a leading blank space for output
lea space, a0 ; alignment.
bsr print_string
cmpi.l #99, d5 ; If execute time is less than 100, then
bgt _no_space ; print another leading blank space.
lea space, a0
bsr print_string
_no_space:
move.l d5, d1 ; Copy execute time for decimal conversion.
trap #4 ; Returns address of decimal string in A0.
bsr.s print_string
lea units_label, a0
bsr.s print_string
close_file:
move.w file_handle, -(sp)
move.w #$3E, -(sp) ; Function = fclose = GEMDOS $3E.
trap #1
addq.l #4, sp
terminate:
move.w #0, -(sp)
trap #1
print_string: ; Expects address of string to be in A0.
pea (a0) ; Push address of string onto stack.
move.w #9, -(sp) ; Function = c_conws = GEMDOS $9.
trap #1 ; GEMDOS call
addq.l #6, sp ; Reset stack pointer to top of stack.
rts
data
space: dc.b " ",0
heading: dc.b $D,$A,"SPEEDTST.TTP Execution Results",$D,$A
dc.b "for ",0
drive_msg: dc.b ", loaded from drive: "
drive: dc.b "A",$D,$A,0
load_time_msg: dc.b $D,$A," Load time: ",0
execute_time_msg: dc.b " Execution time: ",0
units_label: dc.b " milliseconds",$D,$A,0
environ_string: dc.b "TERM",0
command_string: dc.b 0
align
bss
start_time: ds.w 1 ; Value in $4BA just before spawning.
program_name: ds.l 1 ; Pointer to name in basepage command line.
file_handle: ds.w 1 ; Handle for the filename below.
command_line: ds.b 1 ; Unused character count will go here.
filename: ds.b 15 ; File name for redirected output.
ds.l 96 ; Program stack.
stack: ds.l 0 ; Address of program stack.
program_end: ds.l 0
end